<template>
  <div />
</template>

<script>
import {
  setAppId,
  setAppName,
  setPreview
} from '@/utils/auth'
import store from '@/store'
export default {
  name: 'Transfer',
  data() {
    return {
    }
  },
  created: async function() {
    const loading = this.$loading({
      lock: true,
      text: 'Loading',
      spinner: 'el-icon-loading',
      background: 'rgba(0, 0, 0, 0.7)'
    })
    const {
      query
    } = this.$route
    if(query.appId){
      setAppId(query.appId)
    }
    if(query.appName){
      setAppName(query.appName)
    }
    if(query.token){
      this.$store.commit('user/SET_TOKEN', query.token)
    }
    setPreview()
    const routeQuery = {}
    // 拼接非token和appid值
    Object.keys(query).forEach(key => {
      if (!['token', 'appId', 'appName'].includes(key)) {
        routeQuery[key] = query[key]
      }
    })
    const route = this.$router.resolve({
      path: '/',
      query: routeQuery
    })
    console.log(route);
    loading.close()
    await store.dispatch('permission/generateRoutes')
    window.location.href = route.href
  }
}
</script>
